var 引流 = [
    "https://space.bilibili.com/672328094",
    "https://www.bilibili.com/video/BV1FZ4y1F7HH",
    "https://www.bilibili.com/video/BV1FX4y1g7u8",
    "https://www.bilibili.com/video/BV1aK4y1P7Cg",
    "https://www.bilibili.com/video/BV17A411V7Uh",
    "https://www.bilibili.com/video/BV1JV411b7Pc",
    "https://www.bilibili.com/video/BV1AV411v7er",
    "https://www.bilibili.com/video/BV1564y1173Q",

    "https://www.bilibili.com/video/BV1MX4y1N75X",
    "https://www.bilibili.com/video/BV17h411U71w",
    "https://www.bilibili.com/video/BV1ry4y1Y71t",
    "https://www.bilibili.com/video/BV1Sy4y1n7c4",
    "https://www.bilibili.com/video/BV15y4y177uk",
    "https://www.bilibili.com/video/BV1PN411X7QW",
    "https://www.bilibili.com/video/BV1Dp4y1H7iB",
    "https://www.bilibili.com/video/BV1bi4y1P7Eh",
    "https://www.bilibili.com/video/BV1vQ4y1Z7C2",
    "https://www.bilibili.com/video/BV1oU4y1h7Sc",
]

const model_map = new Map();
["Diana_0", "Diana_1"].forEach(function (value, index, array) {
    model_map.set(index, value);
});

const initConfig = {
    mode: "fixed",
    hidden: true,
    content: {
        link: 引流[Math.floor(Math.random() * 引流.length)],
        welcome: ["Hi!"],
        touch: "",
        skin: ["", "蹡蹡！"],
        custom: [
            {"selector": ".comment-form", "text": "Content Tooltip"},
            {"selector": ".home-social a:last-child", "text": "Blog Tooltip"},
            {"selector": ".list .postname", "type": "read"},
            {"selector": ".post-content a, .page-content a, .post a", "type": "link"}
        ],
    },
    night: "toggleNightMode()",
    model: model_json_path,
    tips: true,
    onModelLoad: onModelLoad
}


function onModelLoad(model) {
    const container = document.getElementById("pio-container")
    const canvas = document.getElementById("pio")
    const modelNmae = model.internalModel.settings.name
    const coreModel = model.internalModel.coreModel
    const motionManager = model.internalModel.motionManager

    let touchList = [
        {
            text: "嘉心糖屁用没有",
            motion: "Tap生气 -领结"
        },
        {
            text: "有人急了，但我不说是谁~",
            motion: "Tap= =  左蝴蝶结"
        },
        {
            text: "呜呜...呜呜呜....",
            motion: "Tap哭 -眼角"
        },
        {
            text: "想然然了没有呀~",
            motion: "Tap害羞-中间刘海"
        },
        {
            text: "阿草好软呀~",
            motion: "Tap抱阿草-左手"
        },
        {
            text: "不要再戳啦！好痒！",
            motion: "Tap摇头- 身体"
        },
        {
            text: "嗷呜~~~",
            motion: "Tap耳朵-发卡"
        },
        {
            text: "zzZ。。。",
            motion: "Leave"
        },
        {
            text: "哇！好吃的！",
            motion: "Tap右头发"
        },
    ]

    function playAction(action) {
        action.text && pio_reference.modules.render(action.text)
        action.motion && pio_reference.model.motion(action.motion)

        if (action.from && action.to) {
            Object.keys(action.from).forEach(id => {
                const hidePartIndex = coreModel._partIds.indexOf(id)
                TweenLite.to(coreModel._partOpacities, 0.6, {[hidePartIndex]: action.from[id]});
                // coreModel._partOpacities[hidePartIndex] = action.from[id]
            })

            motionManager.once("motionFinish", (data) => {
                Object.keys(action.to).forEach(id => {
                    const hidePartIndex = coreModel._partIds.indexOf(id)
                    TweenLite.to(coreModel._partOpacities, 0.6, {[hidePartIndex]: action.to[id]});
                    // coreModel._partOpacities[hidePartIndex] = action.to[id]
                })
            })
        }
    }

    canvas.onclick = function () {
        if (motionManager.state.currentGroup !== "Idle") return
        if (modelNmae !== "Diana_0") {
            const action = pio_reference.modules.rand(touchList)
            playAction(action)
        } else {
            const diana_status = parseInt(localStorage.getItem("Diana_status"));
            if (diana_status === 0) {
                const cur_index = pio_reference.modules.idol();
                pio_reference.model = loadlive2d("pio", initConfig.model[cur_index], model => {
                    model.internalModel.settings.name = model_map.get(cur_index);
                    initConfig.onModelLoad && initConfig.onModelLoad(model)
                    initConfig.content.skin && initConfig.content.skin[1] ? pio_reference.modules.render(initConfig.content.skin[1]) : pio_reference.modules.render("Mua~");
                });
                let 嘉然小姐的家 = 嘉然你带我走吧嘉然(".pio-container");
                嘉然小姐的家.classList.remove("pio-container-first");
                localStorage.setItem("Diana_status", 1);
            }
        }


    }

    if (modelNmae === "Diana") {
        container.dataset.model = "Diana"
        initConfig.content.skin[1] = ["我是吃货担当 嘉然 Diana~"]
        playAction({motion: "Tap抱阿草-左手"})

        touchList = [
            {
                text: "嘉心糖屁用没有",
                motion: "Tap生气 -领结"
            },
            {
                text: "有人急了，但我不说是谁~",
                motion: "Tap= =  左蝴蝶结"
            },
            {
                text: "呜呜...呜呜呜....",
                motion: "Tap哭 -眼角"
            },
            {
                text: "想然然了没有呀~",
                motion: "Tap害羞-中间刘海"
            },
            {
                text: "阿草好软呀~",
                motion: "Tap抱阿草-左手"
            },
            {
                text: "不要再戳啦！好痒！",
                motion: "Tap摇头- 身体"
            },
            {
                text: "嗷呜~~~",
                motion: "Tap耳朵-发卡"
            },
            {
                text: "zzZ。。。",
                motion: "Leave"
            },
            {
                text: "哇！好吃的！",
                motion: "Tap右头发"
            },
        ]

        canvas.width = model.width * 1.2
        //canvas.width = model.width * 0.5
        alert(canvas.width);
        const hideParts = [
            "Part5", // 晕
            "neko", // 喵喵拳
            "game", // 左手游戏手柄
            "Part15", // 墨镜
            "Part21", // 右手小臂
            "Part22", // 左手垂下
            "Part", // 双手抱拳
            "Part16", // 惊讶特效
            "Part12" // 小心心
        ]
        const hidePartsIndex = hideParts.map(id => coreModel._partIds.indexOf(id))
        hidePartsIndex.forEach(idx => {
            coreModel._partOpacities[idx] = 0
        })
    }
}


window.onload = 加载圣·嘉然;

var 让我康康 = console.log;

const 一半 = 0.5;
const 屏幕现在多宽捏 = window.screen.width;
const _参考宽度 = 2550;
const _合适的像素 = 300;
const _原本的宽度 = 600;
const 稍微收敛一点 = 20;
const 左边 = "left";
const 七十五 = 75;
const 一 = 1;
const 四分之一 = 0.25;

function _qwq_diana(target) {
    ans = document.querySelector(target);
    return ans;
}

function _scale_str(rate) {
    return "scale(" + (rate) + ")";
}

function _px_str(px) {
    return px + "px";
}

var 嘉然你带我走吧嘉然 = _qwq_diana;
var 喵喵喵 = _scale_str;
var 喵喵喵喵喵 = _px_str;

function 加载圣·嘉然()
{
    pio_reference = new Paul_Pio(initConfig);
    pio_alignment = 左边;
    // Then apply style
    pio_refresh_style();
    const 现在应该多宽 = (屏幕现在多宽捏 / _参考宽度) * _合适的像素;

    let 比率捏 = 一;
    if (七十五 > 现在应该多宽) {
        比率捏 = 四分之一;
    } else {
        比率捏 = 屏幕现在多宽捏 / _参考宽度;
    }
    let 嘉然小姐 = 嘉然你带我走吧嘉然("#pio");
    let 嘉然小姐的家 = 嘉然你带我走吧嘉然(".pio-container");
    嘉然小姐的家.className += " pio-container-first";
    let 嘉然小姐变大变小捏 = 比率捏 * 一半;
    let 嘉然小姐离屏幕左边 = -(_原本的宽度 * (一 - 嘉然小姐变大变小捏) * 一半) + 稍微收敛一点;
    let 嘉然小姐离屏幕下边 = -(_原本的宽度 * (一 - 嘉然小姐变大变小捏) * 一半) - 稍微收敛一点;
    嘉然小姐.style.transform = 喵喵喵(嘉然小姐变大变小捏);
    嘉然小姐.style.left = 喵喵喵喵喵(嘉然小姐离屏幕左边);
    嘉然小姐.style.bottom = 喵喵喵喵喵(嘉然小姐离屏幕下边);
    嘉然小姐的家.style.width = 喵喵喵喵喵(嘉然小姐变大变小捏 * _原本的宽度);
    嘉然小姐的家.style.height = 喵喵喵喵喵(嘉然小姐变大变小捏 * _原本的宽度);
    // 让我康康(嘉然小姐);
    // 让我康康(嘉然小姐的家);
}
